package com.edu.service.handler;


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Date;

/**
 * @Author:wsc
 * @Date:2025/11/10-20:26-28
 */
public class LogHandler implements InvocationHandler {

    private Object o;
    public LogHandler(Object o) {
        this.o = o;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        method.setAccessible(true);
        long sta = System.currentTimeMillis();
        if(!method.getName().contains("sele")){
            System.out.println("执行"+method.getName()+"于"+new Date());
        }
        Object result = method.invoke(o, args);
        if(method.getName().contains("sele")){
            long end = System.currentTimeMillis();
            System.out.println("执行查询方法耗时"+(end - sta)+"ms");
        }
        return result;
    }
}
